#ifndef CONTROLMODE_H
#define CONTROLMODE_H

#include <QWidget>
#include <QDebug>
#include <QBluetoothDeviceInfo>
#include <qbluetoothdevicediscoveryagent.h>
#include <QBluetoothSocket>
#include <QBluetoothUuid>
#include <QBluetoothAddress>
#include <QIODevice>
#include <QThread>
#include "loading.h"

#define ForwardSignal "F"
#define BackSignal "B"
#define LeftSignal "L"
#define RightSignal "R"
#define StopSignal "S"
#define LedRedSignal "D"
#define LedGreenSignal "N"
#define LedBlueSignal "U"
#define LedSignal "E"
#define ServoSignal "O"
#define DistanceSignal "T"
#define SpeedSignal "P"
#define LedOffSignal "G"
#define LedOnSignal "K"

namespace Ui {
class ControlMode;
}

class ControlMode : public QWidget
{
    Q_OBJECT

public:
    explicit ControlMode(QWidget *parent = nullptr);
    ~ControlMode();

private slots:
    void discoverBlueTooth(QBluetoothDeviceInfo info);
    void discoveryFinished();
    void readBluetoothDataEvent();
    void bluetoothConnectedEvent();

    void on_ForwardPushButton_pressed();

    void on_RightPushButton_pressed();

    void on_LeftPushButton_pressed();

    void on_BackPushButton_pressed();

    void on_StopPushButton_pressed();

    void on_horizontalSlider_Led_B_sliderMoved(int position);

    void on_horizontalSlider_Led_G_sliderMoved(int position);

    void on_horizontalSlider_Led_R_sliderMoved(int position);

    void on_pushButton_LedSwitch_clicked();

    void on_pushButton_SetBlue_clicked();

    void on_pushButton_SetGreen_clicked();

    void on_pushButton_SetRed_clicked();

    void on_ForwardPushButton_released();

    void on_LeftPushButton_released();

    void on_RightPushButton_released();

    void on_BackPushButton_released();

    void on_horizontalSlider_Servo_sliderPressed();

    void on_horizontalSlider_Servo_sliderReleased();

    void on_pushButton_ServoLeft_clicked();

    void on_pushButton_ServoCenter_clicked();

    void on_pushButton_ServoRight_clicked();

    void on_verticalSlider_speed_sliderReleased();

private:
    Ui::ControlMode *ui;
    void bluetoothDataSend(QString str);
    void pushButtonStyle(); //按钮样式设置
    void showLedColour(); //显示led的颜色
    QString BTaddress;
    QBluetoothSocket *socket;
    QThread *thread;
    Loading *load;
    int Led_R=0;
    int Led_G=0;
    int Led_B=0;

signals:
    void Lclose();
};

#endif // CONTROLMODE_H
